﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;
using System.Threading;

namespace Test_Appium
{
    [TestClass]
    public class TestABC
    {
        public AndroidDriver<AppiumWebElement> driver;

        [TestInitialize]
        public void BeforeAll()
        {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.SetCapability("device", "Android");
            capabilities.SetCapability(CapabilityType.Platform, "Windows");
            //capabilities.SetCapability("deviceName", "emulator-5554");
            capabilities.SetCapability("deviceName", "4d00b5535ec3a0ad");
            capabilities.SetCapability("platformName", "Android");
            capabilities.SetCapability("platformVersion", "4.4");
            //capabilities.SetCapability("appPackage", "com.android.calculator2");
            //capabilities.SetCapability("appActivity", "com.android.calculator2.Calculator");

            // Samsun Phone Calculator
            //capabilities.SetCapability("appPackage", "com.sec.android.app.popupcalculator");
            //capabilities.SetCapability("appActivity", "com.sec.android.app.popupcalculator.Calculator");

            capabilities.SetCapability("appPackage", "com.microsoft.powerbim");
            capabilities.SetCapability("appActivity", "com.microsoft.powerbi.ui.welcome.WelcomeActivity");

            //capabilities.SetCapability("appPackage", "com.hstdd.test");
            //capabilities.SetCapability("appActivity", "com.hstdd.test.MainActivity");

            driver = new AndroidDriver<AppiumWebElement>(new Uri("http://127.0.0.1:4723/wd/hub/"), capabilities, TimeSpan.FromSeconds(180));
        }


        [TestMethod]
        public void test_calculator_on_emulator()
        {
            var two = driver.FindElement(By.Name("2"));
            two.Click();

            var plus = driver.FindElement(By.Name("+"));
            plus.Click();

            var four = driver.FindElement(By.Name("4"));
            four.Click();

            var equalTo = driver.FindElement(By.Name("="));
            equalTo.Click();

            var results = driver.FindElement(By.ClassName("android.widget.EditText"));
            Assert.AreEqual("6", results.Text);

        }

        [TestMethod]
        public void test_calculator_on_real_phone()
        {
            var two = driver.FindElement(By.Name("2"));
            var four = driver.FindElement(By.Name("4"));

            //var plus = driver.FindElement(By.Name("+"));
            //plus.Click();

            two.Click();
            four.Click();
            two.Click();
            four.Click();


        }

        [TestMethod]
        public void test_pbi()
        {
            Thread.Sleep(50000);
        }

        [TestCleanup]
        public void AfterAll()
        {
            driver.Quit();
        }
    }
}
